<template>
	<view class="page cover-page">
		<!-- <image 
				src="http://122.152.205.72:88/superhero/xman/DarkPhoenix/cover.png" 
				mode="widthFix"
				class="cover-pic"></image> -->
		<image
				:src="cover" 
				mode="widthFix"
				@longpress="operator"
				class="cover-pic"></image>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				cover: ""
			}
		},
		onLoad(params) {
			let cover = params.cover;
			this.cover = cover;
			//设置导航条颜色
			uni.setNavigationBarColor({
				frontColor:"#ffffff",
				backgroundColor:"#000000"
			})
		},
		methods: {
			// 操作
			operator(){
				uni.showActionSheet({
					itemList:["图片下载到本地"],
					success: (res) => {
						// console.log(res)
						// 下载
						if(res.tapIndex === 0){
							uni.showLoading({
								title:"下载中..."
							})
							// 首先把网络图片，下载为临时文件，使用downloadFile，获得tempFilePath
							// 通过uni.saveImageToPhotosAlbum(OBJECT)保持到相册
							// 后期改造为promise方式
							uni.downloadFile({
								url: this.cover,
								success: (res) => {
									let tempFilePath = res.tempFilePath;
									// console.log(res)
									
									uni.saveImageToPhotosAlbum({
										filePath: tempFilePath,
										success: (res) => {
											uni.showToast({
												title:"保存成功",
												duration: 2000
											})
										},
										complete: () => {
											uni.hideLoading();
										}
									})
								}
							})
						}
					}
				})
			}
		}
	}
</script>

<style>
.cover-page{
	display: flex;
	flex-direction: row;
	justify-content: center;
	align-items: center;
	background-color: #000000;
	
	position: fixed;
	
}
.cover-pic{
	
	/* align-self: center; */
}
</style>
